import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    // 当访问地址为 http://localhost:8080/ 时，对应的页面为 layout/index.vue
    path: '/',
    name: 'layout',
    component: () => import('@/layout/index'),
    redirect: 'member',  // 登录首页时默认显示 member 会员管理页面
    children: [
      // 会员管理            
      {
        path: "member",
        name: "member",
        component: () => import("@/views/BmMan/member/index.vue"),
      }
    ]
  },
  // {
  //   path:'/',
  //   name:'layout',
  //   component: ()=>import('@/layout/index')
  // },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
  let token = localStorage.getItem("token");
  if (!token && to.path !== "/login") {
    next({ path: "/login" });
  }
  return next(true);
});


export default router
